<template>
  <Dialog title="以图搜图" v-model="dialogVisible" width="55%">
    <el-upload
      class="upload-demo"
      drag
      :action="upload_url"
      :headers="uploadHeaders"
      :on-success="uploadSuccess"
    >
      <el-icon class="el-icon--upload"><upload-filled /></el-icon>
      <div class="el-upload__text">
        拖拽图片到这里 <em>选择图片</em>
      </div>
    </el-upload>
  </Dialog>
</template>

<script setup lang="ts">
import { UploadFilled } from '@element-plus/icons-vue'
import {getAccessToken, getTenantId} from "@/utils/auth";

const emit = defineEmits(['success'])
const dialogVisible = ref(false)
const upload_url = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/adv/search/picture/features'
const uploadHeaders = {
  Authorization: 'Bearer ' + getAccessToken(),
  'tenant-id': getTenantId()
} // 上传 Header 头
const open = () => {
  dialogVisible.value = true
}
const uploadSuccess = (response: any) => {
  console.log(response)
  dialogVisible.value = false
  emit('success',response.data)
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<style scoped>

</style>
